﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ValidationDemo.Models;

namespace ValidationDemo.Controllers
{
    public class MyValidatorController : Controller
    {
        //
        // GET: /MyValidator/
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Validate(EmployeeInfo model)
        {
            if (ModelState.IsValid)
            {
                ModelState.AddModelError("", "Chúc mừng, dữ liệu đã hợp lệ");
            }
            else
            {
                ModelState.AddModelError("", "Vui lòng sửa các lỗi sau");
            }
            return View("Index");
        }

        //GET
        public ActionResult CustomValidate()
        {
            return View();
        }

        //POST
        [HttpPost]
        [ValidateInput(false)]
        public ActionResult CustomValidate(Custom model)
        {
            if (ModelState.IsValid)
            {
                ModelState.AddModelError("", "Nhập đúng !");
            }
            return View();
        }

        public ActionResult Forgery()
        {
            return View();
        }

        [ValidateAntiForgeryToken, HttpPost]
        public ActionResult Forgery(String Message)
        {
            if (Message != null)
            {
                System.IO.File.AppendAllText(
                    "c:/temp/forgery.txt", Message + "\r\n");
            }
            return View();
        }
	}
}